import axios from 'axios'
export function wait(timeout: number):Promise<void>{
    return new Promise((resolve) => {
        setTimeout(() => {
            resolve()
        }, timeout)
    })
}
export async function requestWithRetry(url: string){
    const MAX_RETRIES = 10;
    for (let i = 0; i <= MAX_RETRIES; i++) {
        console.log("i=",i)
        try { return await axios.get(url); }
        catch (err) {
            const timeout = Math.pow(2, i);
            console.log('Waiting', timeout, 'ms');
            await this.wait(timeout);
            console.log('Retrying', err.message, i);
        }
    }
}